const mysql = require("mysql");
const pool = mysql.createPool({
  host: "localhost",
  database: "flight",
  user: "root",
  password: "root",
});

const query = async (sql) => {
  return new Promise((resolve) => {
    pool.getConnection(function (err, connection) {
      if (err) throw err; // not connected!

      // Use the connection
      connection.query(sql, function (error, results, fields) {
        // When done with the connection, release it.
        connection.release();

        // Handle error after the release.
        if (error) throw error;

        resolve(results);
        // Don't use the connection here, it has been returned to the pool.
      });
    });
  });
};
module.exports = { query, pool };
